<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .wrap {
            margin-top: 20px;
        }

        #title {
            line-height: 60px;
            font-size: 32px;
        }

        .list li {
            line-height: 40px;
            border: 1px dashed #333;
            text-indent: 10px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <h2 id="title">标题</h2>
        <ul class="list">
            <li>01</li>
            <li>02</li>
            <li>03</li>
            <li>04</li>
            <li>05</li>
            <li>06</li>
        </ul>
    </div>
</body>
<script>
    // DOM操作  =>  获取元素,操作元素(修改元素的内容 属性 样式 绑定事件),元素的增删改查

    // 目的: 对DOM操作进行封装,可以方便用户快捷获取元素,操作元素,以及元素的增删改查


    // 字面量对象(最简单的面向对象)
    // list => 也是一个特殊的对象(实例化对象), 如果将方法存出到list上 (list本身 / list.__proto__) 

    /* var list = document.querySelectorAll(".list li");

    list.setText = function (con) {
        for (var i = 0; i < this.length; i++) {
            var ele = this[i];
            ele.innerText = con;
        }
    }

    list.getText = function () {
        return this[0].innerText;
    }

    list.on = function (type, callback) {
        for (var i = 0; i < this.length; i++) {
            var ele = this[i];
            ele.addEventListener(type, callback)
        }
    }
    list.off = function (type, callback) {
        for (var i = 0; i < this.length; i++) {
            var ele = this[i];
            ele.removeEventListener(type, callback)
        }
    }


    list.setText(1111); */


    function GetEle(selector) { // selector 传入css选择器
        var list = document.querySelectorAll(selector);  // 对应选择器获取元素

        list.setText = function (con) {
            for (var i = 0; i < this.length; i++) {
                var ele = this[i];
                ele.innerText = con;
            }
        }

        list.getText = function () {
            return this[0].innerText;
        }

        list.on = function (type, callback) {
            for (var i = 0; i < this.length; i++) {
                var ele = this[i];
                ele.addEventListener(type, callback)
            }
        }
        list.off = function (type, callback) {
            for (var i = 0; i < this.length; i++) {
                var ele = this[i];
                ele.removeEventListener(type, callback)
            }
        }
        return list;
    }

    var titles = GetEle("#title");
    console.log(titles);











</script>

</html>